//
//  ZDDEmoticonToolbar.swift
//  小蜗牛_新浪微博
//
//  Created by 周冬冬 on 16/7/4.
//  Copyright © 2016年 我的mac. All rights reserved.
//

import UIKit
// 表情键盘类型没记
enum ZDDEmoticonToolbarType:Int{
    // 默认
    case Default = 0
    // Emoji表情
    case Emoji = 1
    // 浪小花
    case Lxh = 2
}

class ZDDEmoticonToolbar: UIStackView {

    var currentButton:UIButton?
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
    
    backgroundColor = RandomColor()
    axis = .Horizontal
        distribution = .FillEqually
        let defaultButton = addChildButtons("left", title: "默认", type: .Default)
        let emojiButton = addChildButtons("mid", title: "Emoji", type: .Emoji)
        let lxhButton = addChildButtons("right", title: "浪小花", type: .Lxh)
    
    }
    func buttonClick(button:UIButton){
    
        if currentButton == button {
        
            return
        }
    button.selected = true
        currentButton?.selected = false
        currentButton = button
    
    
    }
    func addChildButtons(imageName:String,title:String,type:ZDDEmoticonToolbarType)->UIButton{
    
        let button = UIButton()
        button.tag = type.rawValue
        button.addTarget(self, action: "buttonClick:", forControlEvents: UIControlEvents.TouchUpInside)
        button.setBackgroundImage(UIImage(named: "compose_emotion_table_\(imageName)_normal"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "compose_emotion_table_\(imageName)_selected"), forState: UIControlState.Selected)
        button.setTitle(title, forState: UIControlState.Normal)
        button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
        button.setTitleColor(UIColor.grayColor(), forState: UIControlState.Selected)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        //添加
        self.addArrangedSubview(button)
        return button
    
    
    
    }
}



















